package com.example.demo.bio;

import java.io.IOException;
import java.io.InputStream;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * Description: <br/>
 *
 * @author liulonglong
 * @taskId <br/>
 * @Date 2019/11/22 14:50
 * @Version 1.0
 */
public class IOServer {

    public static void main(String[] args) throws IOException {
        ServerSocket socket = new ServerSocket(3333);
        new Thread(() -> {
            while (true) {
                try {
                    // 接收到客户端连接
                    Socket accept = socket.accept();
                    new Thread(() -> {
                        try {
                            InputStream inputStream = accept.getInputStream();
                            int len;
                            byte[] buffer = new byte[1024];
                            while ((len = inputStream.read(buffer)) != -1) {
                                System.out.println(new String(buffer, 0, len));
                            }
                        } catch (Exception e) {
                            
                        }
                    }).start();

                } catch (Exception e) {

                }
            }

        }).start();
    }
}
